#!/usr/bin/env python3
# coding: utf-8

import urllib.request, sys, re


# nxt = '12345'
# bitch
nxt = 8022
for ctr in range(400):
    page = urllib.request.urlopen('http://www.pythonchallenge.com' +
                                  '/pc/def/linkedlist.php?nothing={0}'.format(nxt))
    page = page.readall().decode()
    print(page)
    nxt = re.findall(r'next nothing is \d+', page)
    print(nxt)
    nxt = re.findall(r'\d+', nxt[0])[0]
    print(nxt)
    print()
